package arrayandstring;
/**
 * https://leetcode-cn.com/problems/two-sum/
 */
public class E1_TwoSum {
    /**
     * 暴力枚举
     * 时间复杂度 O(n*n) 空间复杂度 O(1)
     */
    public int[] twoSum(int[] nums, int target) {
        int len = nums.length;
        // 第一个元素一定不是数组的最后一个元素
        for (int i = 0; i < len-1; i++) {
            for (int j = i+1; j < len; j++) {
                if (nums[i] + nums[j] == target) {
                    return new int[] {i, j};
                }
            }
        }
        throw new IllegalArgumentException("No two sum solution.");
        // return null;
    }
}
